<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-05 12:05:33
 * @LastEditTime: 2023-04-28 13:53:33
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Http\Services\System;

use App\Http\Services\Service;
use App\Repositories\DepartmentRepository;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class DepartmentService extends Service
    {

    public function __construct(DepartmentRepository $Repository)
        {
        $this->repository = $Repository;
        }
    public function list()
        {
        // DB::enableQueryLog();
        $data = $this->repository->condition(request())->getGrid();
        // dd(DB::getQueryLog());
        return $data;
        }
    public function treelist()
        {
        $data = $this->repository->getMenuList();
        return $data;
        }

    protected function save(Request $request)
        {
        $menu_data = $request->toArray();
        unset($menu_data['children']);
        $data = $this->repository->autosave($menu_data);
        return $data;
        }

    protected function delete(Request $request)
        {
        $this->repository->delete($this->getRequestIds());
        return "delete success!";
        }
    }